/* 
 * File:   common_macros.h
 * Author: gustavo
 *
 * Created on December 30, 2011, 2:39 AM
 */

#ifndef COMMON_MACROS_H
#define	COMMON_MACROS_H

#ifdef	__cplusplus
extern "C" {
#endif

#include <stdlib.h>


	/* = Common definitions ===================================================== */


#ifndef NULL
#define NULL ( (void *)0 )
#endif

	// = Common comparations ===================================================
#ifndef MIN
#define MIN(a,b)	( (a)<(b) ? (a) : (b) )
#endif

#ifndef MAX
#define MAX(a,b)	( (a)>(b) ? (a) : (b) )
#endif

#ifndef XOR
#define XOR( a, b ) ( !(a) ^ !(b) )
#endif

	// = Others ================================================================
#define SWAP( a, b, type ) { type __tmp__swap___; __tmp__swap___= (a); (a) = (b); (b) = __tmp__swap___; }

	// = Common controls =======================================================
#define _exit_if_fail(expr) { if(expr) { } else {  exit(EXIT_FAILURE); } }
#define _return_if_fail(expr) { if(expr) { } else { return; } }
#define _return_val_if_fail(expr, val) { if(expr) { } else { return val; } }

#ifdef	__cplusplus
}
#endif

#endif	/* COMMON_MACROS_H */

